import axios from 'axios'

const API_BASE_URL = '/api'

// 创建axios实例
const apiClient = axios.create({
  baseURL: API_BASE_URL,
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 评论API
export const commentAPI = {
  // 获取文章评论列表
  getCommentsByArticleId(articleId) {
    return apiClient.get(`/comments/article/${articleId}`)
  },

  // 添加评论
  addComment(comment) {
    return apiClient.post('/comments', comment)
  },

  // 点赞评论
  likeComment(commentId, nickname) {
    return apiClient.post(`/comments/${commentId}/like`, null, {
      params: { nickname }
    })
  },

  // 点赞文章
  likeArticle(articleId, nickname) {
    return apiClient.post(`/comments/article/${articleId}/like`, null, {
      params: { nickname }
    })
  },

  // 检查评论点赞状态
  checkCommentLikeStatus(commentId, nickname) {
    return apiClient.get(`/comments/${commentId}/like-status`, {
      params: { nickname }
    })
  },

  // 检查文章点赞状态
  checkArticleLikeStatus(articleId, nickname) {
    return apiClient.get(`/comments/article/${articleId}/like-status`, {
      params: { nickname }
    })
  }
}

export default commentAPI
